<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>控制中心</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta content="telephone=no" name="format-detection" />
    <script src="js/vue.js"></script>
    <link rel="stylesheet" href="js/layui/css/layui.css">
    <style>
        body{
            padding: 0;
            margin: 0;
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<form class="layui-form" action="" lay-filter="example">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">最低等级</label>
            <div class="layui-input-inline">
                <input  name="startLv" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>

<script src="js/layui/layui.all.js"></script>
<script>
    var $;
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //监听提交
        $=layui.jquery;
        form.on('submit(demo1)', function(data){
            var json=JSON.stringify(data.field);
            post("/api/danmu/updateSetting",json,function (res) {
                if(res.result){
                    layer.msg("提交失败")
                }else {
                    layer.msg("提交成功")
                }
            },function (err) {

            })

            return false;
        });

        //表单初始赋值

        $.get("/api/danmu/getSetting",function (res) {
            if(res.result){
                var data=res.data;
                form.val('example', {
                    "startLv": data.startLv
                })
            }
        })

    });

    var post=function(url,data,success,error){
        $.ajax({
                type: "post",
                url: url,
                data: data,
                contentType: "application/json; charset=utf-8",
//                dataType: "json",
//                    async: true, // 使用同步方式
                success: success,error:error}
        );
    }
</script>

</body>
</html>